<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>我的餐厅信息</title>
    <style>
    
    body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }

        .navbar {
            background-color: #d2a679;
            overflow: hidden;
            border-bottom: 2px solid #ccc;
        }

        .navbar a {
            float: left;
            display: block;
            color: #000;
            text-align: center;
            padding: 14px 20px;
            text-decoration: none;
            font-size: 17px;
        }

        .navbar a:hover {
            background-color: #ddd;
            color: black;
        }

        .navbar a.active {
            background-color: #ff704d;
            color: white;
        }

        .container {
            max-width: 800px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
    
    
        body {
            font-family: Arial, sans-serif;
            background-color: #f9f9f9;
            margin: 0;
            padding: 0;
        }

        .container {
            max-width: 800px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        h1 {
            margin-bottom: 20px;
            color: #333;
            text-align: center;
        }

        p {
            margin-bottom: 10px;
        }

        .info {
            border-top: 1px solid #ccc;
            margin-top: 20px;
            padding-top: 10px;
        }
    </style>
</head>
<body>

<div class="navbar">
        <a href="Order Status.jsp">点餐状态</a>
        <a href="BOH.jsp">后厨状态</a>
        <a href="order.jsp">今日订单</a>
        <a href="Menu Management.jsp">菜品管理</a>
        <a href="Sales Statistics.jsp">营业统计</a>
        <a href="aboutme.jsp"  class="active">我的</a>
    </div>
    
    <div class="container">
        <h2>输入餐厅ID进行筛选</h2>
        <!-- 用户输入筛选条件的表单 -->
        <form action="aboutme.jsp" method="get">
            <label for="restaurantId">餐厅ID:</label>
            <input type="text" id="restaurantId" name="restaurantId">
            <button type="submit">筛选</button>
        </form>
    </div>


    <div class="container">
        <h2>筛选结果</h2>
        <table>
            <thead>
                <tr>
                    <th>餐馆ID</th>
                    <th>餐馆名称</th>
                    <th>联系电话</th>
                    <th>地址</th>
                </tr>
            </thead>
            <tbody>
                <% 
                // 获取请求中的restaurantId参数
                String filterRestaurantId = request.getParameter("restaurantId");
                if (filterRestaurantId != null && !filterRestaurantId.isEmpty()) {
                    String sql = "SELECT * FROM restaurants WHERE restaurant_id = ?";
                    try (Connection conn = com.myweb.DBTools.getConn();
                         PreparedStatement pstmt = conn.prepareStatement(sql)) {
                        pstmt.setString(1, filterRestaurantId);
                        try (ResultSet rs = pstmt.executeQuery()) {
                            if (!rs.next()) {
                                %><tr><td colspan="4">没有找到匹配的餐馆记录。</td></tr><%
                            } else {
                                do {
                                    %>
                                    <tr onclick="fillform(this)">
                                        <td><%= rs.getString("restaurant_id") %></td>
                                        <td><%= rs.getString("restaurant_name") %></td>
                                        <td><%= rs.getString("restaurant_phone") %></td>
                                        <td><%= rs.getString("restaurant_address") %></td>
                                    </tr>
                                    <%
                                } while (rs.next());
                            }
                        } // try-with-resources for ResultSet
                    } catch (SQLException e) {
                        // 向用户显示一个友好的错误消息
                        out.println("<tr><td colspan='4'>发生数据库查询错误：" + e.getMessage() + "</td></tr>");
                        e.printStackTrace(); // 仅用于调试，生产环境中应避免
                    }
                } else {
                    %><tr><td colspan="4">请输入餐馆ID进行筛选。</td></tr><%
                }
                %>
            </tbody>
        </table>
    </div>

</body>
</html>